<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class admin_model extends CI_Model{
    var $table          = "tbl_admin";
    var $tbl_state      = "master_state";
    var $primarykey     = "username";
    
    public function __construct()
    {
        parent::__construct();
    }
    function get_paged_list($limit = 20, $offset = 0, $order_column='datecreated', $order_type='DSC'){
        if(empty($order_column)||empty($order_type)){
            $this->db->order_by("datecreated",'DSC');	
    	}
    	else{
            $this->db->order_by($order_column,$order_type);
            return $this->db->get($this->table, $limit, $offset);
    	}
    }
    function get(){
        $q = $this->db->query("SELECT * FROM `$this->table`");
        return $q->result();
    }
    function save($isi){
        $this->db->insert($this->table,$isi);
    }
    function update($id,$array){
        $this->db->where($this->primarykey,$id);	
        if($this->db->update($this->table,$array)) return TRUE;
        else return FALSE;
    }
    function login_check($username,$password){
        $q = $this->db->query("SELECT * FROM `$this->table` WHERE `username` = '$username' AND `password` = '$password'");
        if($q->num_rows() > 0)return true;
        else return false;
    }
    function select_id($id){
        $q = $this->db->query("SELECT * FROM `$this->table` as A LEFT OUTER JOIN `$this->tbl_state` as C ON A.`state_id` = C.`state_id` WHERE `username` = '$id'");
        if($q->num_rows() > 0)return $q->row();
        else return false;
    }
    function get_by_id($id){
        $kueri = "SELECT * FROM `$this->table` as A LEFT OUTER JOIN `$this->tbl_state` as C ON A.`state_id` = C.`state_id` WHERE `id_admin` = '$id'";
        $q = $this->db->query($kueri);
        return $q->result();
    }
    function check_pass($id,$pass){
        $q = $this->db->query("SELECT * FROM `".$this->table."` WHERE `id_admin` = '".$id."' AND `password` = '".$pass."'");
        return $q->num_rows();
    }
}
/* End of file admin_model.php */
/* Location: ./application/models/model_kasus.php */
